﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace Frame.Pages
{
    public abstract class DetailViewPage:BasePage
    {
        protected DevExpress.Web.ASPxRoundPanel.ASPxRoundPanel Detailpanel;
        /// <summary>
        /// 查询命令语句
        /// </summary>
        protected abstract string QueryCommandString
        {
            get;
        }
        /// <summary>
        /// 查询命令参数
        /// </summary>
        protected abstract SqlParameter[] QueryParameters
        {
            get;
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (!IsPostBack && !IsCallback)
            {
                DataMapping();
            }
            
        }
        /// <summary>
        /// 使用反射的映射函数
        /// </summary>
        private void DataMapping()
        {
            using (SqlDataReader dr = Global.GlobalSqlHelper.GetSQLDataReader(QueryCommandString))
            {

                if (dr.Read())
                {
                    for (int i = 0; i < dr.FieldCount; i++)
                    {
                        DevExpress.Web.ASPxEditors.ASPxLabel editor =
                            (DevExpress.Web.ASPxEditors.ASPxLabel)Detailpanel.FindControl(string.Format("View_{0}", dr.GetName(i)));
                        editor.Text = dr.GetValue(i).ToString();
                    }
                }
                dr.Close();
            }
        }
    }
}
